import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const Home = () => import('views/home/Home')
const Profile = () => import('views/profile/Profile')
const Search = () => import('views/search/Search')
const Detail = () => import('views/detail/Detail')
const Publish = () => import ('views/publish/Publish')
const Login = () => import ('views/login/Login')
const Register = () => import ('views/register/Register')
const ForgetPass = () => import ('views/forgetPass/ForgetPass')
const ResetPass = () => import ('../views/resetPass/ResetPass')


// Profile子组件
const ProfileCollectInterview = () => import('../views/profile/childComps/profileCollectInterview/ProfileCollectInterview')
const ProfileCollectQuestion = () => import('../views/profile/childComps/profileCollectQuestion/ProfileCollectQuestion')
const ProfileMessage = () => import('../views/profile/childComps/profileMessage/ProfileMessage')
const ProfilePublish = () => import('../views/profile/childComps/profilePublish/ProfilePublish')
const ProfileSetAccount = () => import('../views/profile/childComps/profileSetAccount/ProfileSetAccount')
const ProfileSetPersonal = () => import('../views/profile/childComps/profileSetPersonal/ProfileSetPersonal')

// Search子组件
const SearchFirm = () => import("../views/search/childComps/searchFirm/SearchFirm")
const SearchPost = () => import("../views/search/childComps/searchPost/SearchPost")
const SearchQuestionModule = () => import("../views/search/childComps/searchQuestion/SearchQuestionModule")
const QueryQuestion = () => import("../views/search/childComps/searchQuestion/QueryQuestion")
const CommonQuestion = () => import("../views/search/childComps/searchQuestion/CommonQuestion")
const  SearchQuestionDetail = () => import("../views/search/childComps/searchQuestion/SearchQuestionDetail")
const  FirmDetail = () => import("../views/search/childComps/searchFirm/firmDetail/FirmDetail")


// Publish子组件
const BaseInfo = () => import("../views/publish/childComps/BaseInfo")
const DetailInfo = () => import("../views/publish/childComps/DetailInfo")

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: Home,
    meta: {
      title: '首页'
    }
  },
  {
    path: '/profile/:userId',
    component: Profile,
    meta: {
      title: '个人中心'
    },
    children: [
      {
        path: '',
        redirect: 'publish'
      },
      {
        path: 'publish',
        component: ProfilePublish
      },
      {
        path: 'collect/interview',
        component: ProfileCollectInterview
      },
      {
        path: 'collect/question',
        component: ProfileCollectQuestion
      },
      {
        path: 'setting/account',
        component: ProfileSetAccount
      },
      {
        path: 'setting/personal',
        component: ProfileSetPersonal
      },
      {
        path: 'message',
        component: ProfileMessage
      },
    ]
  },
  {
    path: '/search',
    component: Search,
    meta: {
      title: '搜索结果'
    },
    children: [
      {
        path: 'firm',
        component: SearchFirm,
      },
      {
        path: 'firm/detail/:firmName',
        component: FirmDetail
      },
      {
        path: 'post',
        component: SearchPost
      },
      {
        path: 'questionModule',
        component: SearchQuestionModule
      },
      {
        path: 'queryQuestion',
        component: QueryQuestion
      },
      {
        path: 'commonQuestion',
        component: CommonQuestion
      },
      {
        path: 'question/detail',
        name: 'questionDetail',
        component: SearchQuestionDetail
      },
    ]
  },
  {
    path: '/detail/:articleId',
    component: Detail,
    meta: {
      title: '详情'
    },
  },
  {
    path: '/publish',
    component: Publish,
    meta: {
      title: '发布面经'
    },
    children: [
      {
        path: '',
        redirect: 'base'
      },
      {
        path: 'base',
        name: 'base',
        component: BaseInfo
      },
      {
        path: 'detail',
        name: 'detail',
        component: DetailInfo
      }
    ]
  },
  {
    path: '/login',
    component: Login,
    meta: {
      title: '登录'
    },
  },
  {
    path: '/register',
    component: Register,
    meta: {
      title: '注册'
    },
  },
  {
    path: '/forgetPass',
    component: ForgetPass,
    meta: {
      title: '忘记密码'
    },
  },
  {
    path: '/resetPass',
    component: ResetPass
  }
]

const router = new VueRouter({
  routes,
  mode: 'history'
})

router.beforeEach((to, from, next) => {
  next()
  document.title = to.matched[0].meta.title
})

export default router
